package windbell.domain.risk.impl;

import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import windbell.domain.risk.RiskCheckFromSchedule;
import windbell.domain.risk.RiskCheckGenerator;
import windbell.domain.risk.RiskCheckTemplate;
import windbell.domain.risk.impl.RiskCheckGeneratorImpl;
import windbell.domain.risk.impl.RiskCheckSourceImpl;
import windbell.domain.risk.proxy.RiskCheckFromScheduleProxy;

@Entity
@DiscriminatorValue("RISKCHECKFROMSCHEDULE_TYPE")
public class RiskCheckFromScheduleImpl extends RiskCheckSourceImpl implements RiskCheckFromSchedule {
  public RiskCheckFromScheduleImpl() {
    super();
  }
  
  public RiskCheckFromScheduleImpl(final RiskCheckTemplate checkTemplate) {
    super( checkTemplate);
    
  }
  
  @JoinColumn(name = "generator_id")
  @ManyToOne(targetEntity = RiskCheckGeneratorImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RiskCheckGenerator generator;
  
  public RiskCheckGenerator getGenerator() {
    return this.generator;
  }
  
  public RiskCheckFromSchedule setGenerator(final RiskCheckGenerator generator) {
    this.generator = generator;
    return this;			
    
  }
  
  public RiskCheckTemplate getCheckTemplate() {
    RiskCheckTemplate _checkTemplate = this.generator.getCheckTemplate();
    return _checkTemplate;
  }
  
  public String getEntityName() {
    RiskCheckTemplate _checkTemplate = this.generator.getCheckTemplate();
    String _name = _checkTemplate.getName();
    return _name;
  }
  
  public static RiskCheckFromSchedule create(final RiskCheckTemplate checkTemplate, final IObjectFactory objectFactory) {
    windbell.domain.risk.RiskCheckFromSchedule riskCheckFromSchedule = new windbell.domain.risk.impl.RiskCheckFromScheduleImpl(
    	checkTemplate
    );
    objectFactory.create(riskCheckFromSchedule);
    return riskCheckFromSchedule;			
    
  }
  
  public static RiskCheckFromSchedule createRiskCheckFromScheduleImpl(final RiskCheckTemplate checkTemplate, final IObjectFactory objectFactory, final Procedure1<RiskCheckFromSchedule> init) {
    windbell.domain.risk.RiskCheckFromSchedule riskCheckFromSchedule = new windbell.domain.risk.impl.RiskCheckFromScheduleImpl(
    	checkTemplate
    );
    objectFactory.create(riskCheckFromSchedule);
    init.apply(riskCheckFromSchedule);
    return riskCheckFromSchedule;			
    
  }
  
  public RiskCheckFromScheduleProxy toProxy() {
    windbell.domain.risk.proxy.RiskCheckFromScheduleProxy proxy = new windbell.domain.risk.proxy.RiskCheckFromScheduleProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    if(this.getStatus()!=null)proxy.setStatus(this.getStatus().name());;
    return proxy;
    
  }
}
